import { local } from '@/utils/jcore/storage'

// app vuex
const state = {
  selectRouteName: '',
  sideTheme: '1',
  menuList: [],
  sidebarList: [],
  sidebar: {
    opened: local.get('sidebarStatus') ? !!local.get('sidebarStatus') : true,
    withoutAnimation: false
  },
  userInfo: {}
}

const mutations = {
  setSelectRouteName: (store, name) => {
    store.selectRouteName = name
  },
  setSideTheme: (store, name) => {
    store.sideTheme = name
  },
  setMenuList: (store, data) => {
    store.menuList = data
  },
  setSidebarList: (store, data) => {
    store.sidebarList = data
  },
  setUserInfo: (store, data) => {
    store.userInfo = data
  },
  TOGGLE_SIDEBAR: (state) => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      local.set('sidebarStatus', 1)
    } else {
      local.set('sidebarStatus', 0)
    }
  }
}

const actions = {
  setSideTheme({ commit }, name) {
    commit('setSideTheme', name)
  },
  setSelectRouteName({ commit }, name) {
    commit('setSelectRouteName', name)
  },
  setMenuList({ commit }, data) {
    commit('setMenuList', data)
  },
  setSidebarList({ commit }, data) {
    commit('setSidebarList', data)
  },
  setUserInfo({ commit }, data) {
    commit('setUserInfo', data)
  },
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
